import { cloneDeep, } from 'lodash-es';

let logininforList: LogininforRecord[] = [
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 126,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-10 23:52:16"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 125,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-10 16:14:15"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 124,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-10 16:04:22"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 123,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-10 15:28:23"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 122,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-09 16:46:45"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 121,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 20:11:23"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 120,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 19:40:19"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 119,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 18:42:18"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 118,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 00:49:57"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 117,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "退出成功",
    "loginTime": "2024-07-08 00:49:49"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 116,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 00:49:44"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 115,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "退出成功",
    "loginTime": "2024-07-08 00:49:23"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 114,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 00:48:14"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 113,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "退出成功",
    "loginTime": "2024-07-08 00:47:15"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 112,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 00:41:24"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 111,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "退出成功",
    "loginTime": "2024-07-08 00:41:07"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 110,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-08 00:41:03"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 109,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "退出成功",
    "loginTime": "2024-07-08 00:40:58"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 108,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 22:35:08"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 107,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 21:06:27"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 106,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 21:03:14"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 105,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 19:57:45"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 104,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 19:40:00"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 103,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 18:03:07"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 102,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 17:47:16"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 101,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "登录成功",
    "loginTime": "2024-07-07 17:45:45"
  },
  {
    "createBy": null,
    "createTime": null,
    "updateBy": null,
    "updateTime": null,
    "remark": null,
    "infoId": 100,
    "userName": "admin",
    "status": "0",
    "ipaddr": "127.0.0.1",
    "loginLocation": "内网IP",
    "browser": "Chrome 12",
    "os": "Windows 10",
    "msg": "退出成功",
    "loginTime": "2024-07-07 17:45:40"
  }
];

const mocks: MockRecord[] = [
  {
    method: "get",
    url: "/api/monitor/logininfor/list",
    response(option) {
      const copyList = cloneDeep(logininforList);

      let resList = logininforList;

      if (option.query.pageNum) {
        resList = copyList.splice((option.query.pageNum - 1) * option.query.pageSize, option.query.pageSize);
      }

      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        total: logininforList.length,
        ...(option.query.pageNum ? { rows: resList } : { data: resList })
      }

      return resData;
    }
  },
  {
    method: "get",
    url: "/api/monitor/logininfor/:infoId",
    response(option) {
      const resLogininfor = logininforList.find(item => item.infoId == option.query.infoId);

      const resData: responseType = {
        code: resLogininfor ? 200 : 500,
        msg: resLogininfor ? "查询成功" : "查询失败",
        data: resLogininfor,
      }

      return resData;
    }
  },
  {
    method: "post",
    url: "/api/monitor/logininfor",
    response(option) {
      const newLogininfor = option.body;

      newLogininfor.infoId = logininforList.length + 1;
      logininforList.unshift(newLogininfor);

      const resData: responseType = {
        code: 200,
        msg: "新增成功",
      }

      return resData;
    }
  },
  {
    method: "put",
    url: "/api/monitor/logininfor",
    response(option) {
      const newLogininfor = option.body;

      const index = logininforList.findIndex(item => item.infoId == newLogininfor.infoId);

      logininforList.splice(index, 1, newLogininfor);

      const resData: responseType = {
        code: 200,
        msg: "修改成功",
      }

      return resData;
    }
  },
  {
    method: "delete",
    url: "/api/monitor/logininfor/:infoIds",
    response(option) {
      const infoIds = option.query.infoIds.split(',');

      const filterList = logininforList.filter(item => !infoIds.includes(String(item.infoId)));

      logininforList = filterList;

      const resData: responseType = {
        code: 200,
        msg: "删除成功",
      }
      return resData;
    }
  }
];

export default mocks;